import time

from selenium.webdriver.common.by import By

from Pages import BasePage


class LoginAdmin(BasePage.Action):

    #用户名
    userid_loc = (By.XPATH,"//input[@id='username']")
    time.sleep(1)
    #密码
    password_loc = (By.XPATH,"//input[@id = 'password']")
    time.sleep(1)
    #登录按钮
    loginbutton_loc = (By.XPATH,"//input[@id='authorityLoginBtn']")
    time.sleep(1)
    #同程管家登录
    starFish_loc = (By.XPATH, "//img[@id='starfish-avatar']")
    time.sleep(1)
    #账号密码登录
    loginByPassword_loc = (By.XPATH, "//a[@id='loginByPassword']")
    time.sleep(1)
    #一周内免登陆
    weeklyFree = (By.XPATH, "//label[@id='isNoLoginWeeklyLabel']")
    #模块取消（没啥用）
    backToLogin_loc = (By.CSS_SELECTOR, ".modal-cancel")
    #登录提示
    loginWarning_loc = (By.CSS_SELECTOR, "[class*='login-warn']")
    #
    sayHi_xpath = (By.XPATH, "//div[@class='headerWrapper']//span[contains(text(),'您好')]")

    # Action
    #打开浏览器
    def open(self):
        # self._open(self.base_url, self.pagetilte)
        self._open(self.base_url)
    #点击同程管家登录
    def quickLogin(self):
        self.find_element(*self.starFish_loc).click()
    #输入用户名
    def input_userid(self, userid):
        self.find_element(*self.userid_loc).send_keys(userid)
    #输入密码
    def input_password(self, password):
        self.find_element(*self.password_loc).send_keys(password)
    #点击登录
    def click_login(self):
        self.wait_loadingmask_disappear()
        self.find_element(*self.loginbutton_loc).click()
    #一周内免登录
    def click_weeklyFree(self):
        self.smart_click(*self.weeklyFree)
    #切换账号密码登录
    def switchToLoginByPassword(self):
        self.find_element(*self.loginByPassword_loc).click()

    def alreadyLogin(self):
        if self.find_element(*self.sayHi_xpath):
            return True



